<template>
  <view class="contenter">
    <indextime @time="time" :times="form" :index="index"></indextime>
    <scroll-view  scroll-y="true" class="scroll-Y" @scrolltolower="onReachBottom" >
      <view>
        <view class="bg">
          <view class="name">销售额</view>
          <view class="price">¥ {{data.sales}}</view>
        </view>
        <view class="item u-flex flex_bt" v-for="(item,index) in list">
          <view>
            <view class="name u-pd-b-10">项目名称：{{item.name}}</view>
            <view class="u-pd-b-10">订单号：{{item.orderid}}</view>
            <view>核销时间：{{item.buytime}}</view>
          </view>

          <view class="price">+{{item.price}}</view>
        </view>
      </view>

      <view class="loading_text">
        <text>{{loadingText }}</text>
      </view>
    </scroll-view>

  </view>
</template>

<script>
import Indextime from "../../components/index/indexTime";
export default {
  name: "salesVolume",
  components: {Indextime},
  data(){
    return{
      data:{},
      loadingText:'',
      list:[],
      allpage:'',
      index:'',
      type:'',//1是当日 2是当月
      page:1,
      form:{
        end_time:'',
        start_time:'',
      },
    }
  },
  onLoad(option){
    this.type = option.type
    if(this.type == 2){
      this.yearChange()
      this.index = 2
    }else {
      this.NewDay()
    }
    this.setData()
  },
  methods:{
    setData(){

      let form = {
        start_time:this.form.start_time || '',
        end_time:this.form.end_time || '',
        page:this.page,
      }
      let that = this
      this.$api.salesList(form).then(res => {
        this.data = res.data
        this.allpage = res.data.order.last_page
        that.list = [...that.list,...res.data.order.data]
      })
    },
    //筛选时间
    time(time){
      this.form.start_time = time.start_time
      this.form.end_time = time.end_time
      this.page = 1
      this.list = []
      this.setData()
    },
    //上拉加载
    onReachBottom(){
      if(this.page>=this.allpage){
        this.loadingText="已经到底啦！"
        return ;
      }else{
        this.loadingText = '加载中....'
      }
      this.page ++
      this.setData()
    },
  },
}
</script>

<style scoped lang="scss">
  .bg{
    background: url("/static/user/xiaos.png") no-repeat;
    background-size: 100%;
    width: 100%;
    height: 206rpx;
    margin-top: 20rpx;
    padding: 16rpx 80rpx;
    .name{
      font-size: 32rpx;
      color: white;
      padding-bottom: 20rpx;
    }
    .price{
      color: white;
      font-size: 56rpx;
    }
  }
  .item{
    margin-top: 20rpx;
    padding: 20rpx 32rpx;
    background: white;
    width: 100%;
    font-size: 28rpx;
    color: #4B4B4B;
    .name{
      font-size: 36rpx;
    }
    .price{
      font-size: 36rpx;
      color: $uni-color-price;
    }
  }
</style>